package com.larissa.quiz;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity implements View.OnClickListener{

    private int currentIdx=0;
    private Question[] Questions=new Question[]{
            new Question(R.string.test_bj,true),
            new Question(R.string.test_dc,false),
            new Question(R.string.test_london,true),
            new Question(R.string.test_tokyo,true)
    };
    private int count=0;

    private TextView mQuestionTextView;
    private Button mBtnTrue;
    private Button mBtnFalse;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        mQuestionTextView=(TextView) findViewById(R.id.tx_question);
        mBtnTrue=(Button) findViewById(R.id.btn_true);
        mBtnFalse=(Button) findViewById(R.id.btn_false);

        mBtnTrue.setOnClickListener(this);
        mBtnFalse.setOnClickListener(this);


//        mQuestionTextView.setText(Questions[currentIdx].getQuestionId());
        showQuestion();
    }

//    public void clickTrue(View view){
//        if(Questions[currentIdx].isQuestionAnswer()){
//            count++;
//        }
//        currentIdx++;
//        if(currentIdx==Questions.length){
//            mBtnTrue.setEnabled(false);
//            mBtnFalse.setEnabled(false);
//            Toast.makeText(this,String.format("%s questions are right",count),Toast.LENGTH_LONG).show();
//        }else{
//            mQuestionTextView.setText(Questions[currentIdx].getQuestionId());
//        }
//    }
//
//    public void clickFalse(View view){
//        if(!Questions[currentIdx].isQuestionAnswer()){
//            count++;
//        }
//        currentIdx++;
//        if(currentIdx==Questions.length){
//            mBtnTrue.setEnabled(false);
//            mBtnFalse.setEnabled(false);
//            Toast.makeText(this,String.format("%s questions are right",count),Toast.LENGTH_LONG).show();
//        }else{
//            mQuestionTextView.setText(Questions[currentIdx].getQuestionId());
//        }
//    }

    public void clickMethod(View view){
        boolean clickAnswer=view.getId()==R.id.btn_true? true:false;
        if(clickAnswer==Questions[currentIdx].isQuestionAnswer()){
            count++;
        }
        currentIdx++;
        showQuestion();
    }

    private void showQuestion(){
        if(currentIdx==Questions.length){
            mBtnTrue.setEnabled(false);
            mBtnFalse.setEnabled(false);
            Toast.makeText(this,String.format("%s questions are right",count),Toast.LENGTH_LONG).show();
        }else{
            mQuestionTextView.setText(Questions[currentIdx].getQuestionId());
        }
    }

    @Override
    public void onClick(View view) {
        boolean clickAnswer=view.getId()==R.id.btn_true? true:false;
        if(clickAnswer==Questions[currentIdx].isQuestionAnswer()){
            count++;
        }
        currentIdx++;
        showQuestion();
    }
}